import 'dart:io';

import 'package:date_format/date_format.dart';
import 'package:package_info/package_info.dart';
import 'package:tender_flutter/page/goods/api/api_goods.dart';
import 'package:tender_flutter/page/goods/model/goods_entity.dart';
import 'package:tender_flutter/page/home/model/city_entity.dart';

/// 全局数据共享类
class DataManager {
  /// 当前定位或者用户手动选择的城市信息
  CityEntity cityEntity;

  /// 是否出于审核状态（苹果）
  bool isAppstore = false;

  // 工厂模式
  factory DataManager() => _getInstance();

  static DataManager get instance => _getInstance();

  static DataManager _instance;

  DataManager._internal() {
    // 初始化
  }

  static DataManager _getInstance() {
    if (_instance == null) {
      _instance = new DataManager._internal();
    }
    return _instance;
  }

  /// 审核开关是否以打开
  /// 只有上架的版本和后台填写的buildCode一致 次步骤才有效
  Future checkReviewState() async {
    if (Platform.isAndroid) {
      return;
    }
    // DateTime _nowDate = DateTime.now();
    // String time = formatDate(_nowDate, [yyyy,'-',mm,'-',dd]);
    // if (time == "2021-05-11" || time == "2021-05-12"){
    //   _instance.isAppstore = true;
    // }
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    var response = await ApiGoods.showGoods<Goods>();
    Goods entity = response.result;
    if (entity != null) {
      if (entity.code == int.parse( packageInfo.buildNumber)){
        _instance.isAppstore = entity.isShow;
      }
    }
  }
}
